Skip to contentSkip to conversation

Change in openvpn[master]: ssl: Clean up type handling in parse_early_negotiation_tlvs()

Openvpn-devel In review flichtenheld (Code Review) 2 participants 9 messages Oct 24, 2025 – Nov 17, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1761324750000.Ie7ad637223c332f7611c09b20a8d7a3a92d97ec7@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1302?usp=email

to review the following change.

Change subject: ssl: Clean up type handling in parse_early_negotiation_tlvs()
......................................................................

ssl: Clean up type handling in parse_early_negotiation_tlvs()

buf_read_u16 does not return uint16_t.

Change-Id Ie7ad637223c332f7611c09b20a8d7a3a92d97ec7

---
M src/openvpn/ssl.c

1 file changed, 4 insertions(+), 13 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/02/1302/1

src/openvpn/ssl.c +4 -13
index 819a1ef..9a3ba88 100644
@@ -2195,11 +2195,6 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 /**
  * Handle reading key data, peer-info, username/password, OCC
  * from the TLS control channel (cleartext).
@@ -2530,9 +2525,9 @@
             goto error;
         }
         /* read type */
-        uint16_t type = buf_read_u16(buf);
-        uint16_t len = buf_read_u16(buf);
-        if (buf_len(buf) < len)
+        int type = buf_read_u16(buf);
+        int len = buf_read_u16(buf);
+        if (type < 0 || len < 0 || buf_len(buf) < len)
         {
             goto error;
         }
@@ -2544,7 +2539,7 @@
                 {
                     goto error;
                 }
-                uint16_t flags = buf_read_u16(buf);
+                int flags = buf_read_u16(buf);
 
                 if (flags & EARLY_NEG_FLAG_RESEND_WKC)
                 {
@@ -3975,10 +3970,6 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 void
 tls_prepend_opcode_v1(const struct tls_multi *multi, struct buffer *buf)
 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1302?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie7ad637223c332f7611c09b20a8d7a3a92d97ec7
Gerrit-Change-Number: 1302
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1302?usp=email )

Change subject: ssl: Clean up type handling in parse_early_negotiation_tlvs()
......................................................................

Patch Set 6: Code-Review-1

(1 comment)

Patchset:

PS6:
I don't like this one. Looking at buf_read_u16(), this is really an unsigned type, so parsing this as int and checking for len < 0 is just wrong.

Since there are not very many callers, I would tend to actually make it return a proper uint16_t - which is what ntohs(ret) produces anyway - and fix those callers that need to be able to deal with negative values (if any).

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1302?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie7ad637223c332f7611c09b20a8d7a3a92d97ec7
Gerrit-Change-Number: 1302
Gerrit-PatchSet: 6
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sun, 16 Nov 2025 18:53:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1302?usp=email )

Change subject: ssl: Clean up type handling in parse_early_negotiation_tlvs()
......................................................................

Patch Set 6: -Code-Review

(1 comment)

Patchset:

PS6:
I take that back, we actually do need -1 to signal buf_read() error. Will do a new review...

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1302?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie7ad637223c332f7611c09b20a8d7a3a92d97ec7
Gerrit-Change-Number: 1302
Gerrit-PatchSet: 6
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sun, 16 Nov 2025 19:12:23 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1302?usp=email )

Change subject: ssl: Clean up type handling in parse_early_negotiation_tlvs()
......................................................................

Patch Set 6:

(1 comment)

Patchset:

PS6:

Quoted 1 line

I don't like this one. […]

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1302?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie7ad637223c332f7611c09b20a8d7a3a92d97ec7
Gerrit-Change-Number: 1302
Gerrit-PatchSet: 6
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sun, 16 Nov 2025 19:12:36 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>

#5 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1302?usp=email )

Change subject: ssl: Clean up type handling in parse_early_negotiation_tlvs()
......................................................................

Patch Set 6: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1302?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie7ad637223c332f7611c09b20a8d7a3a92d97ec7
Gerrit-Change-Number: 1302
Gerrit-PatchSet: 6
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sun, 16 Nov 2025 21:54:18 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

#6 lore raw

PATCH v6 1/1 ssl: Clean up type handling in parse_early_negotiation_tlvs()

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

buf_read_u16 does not return uint16_t.

Change-Id Ie7ad637223c332f7611c09b20a8d7a3a92d97ec7

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1302
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1302
This mail reflects revision 6 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

src/openvpn/ssl.c +4 -13
index 555f483..6f15ebe 100644
@@ -2194,11 +2194,6 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 /**
  * Handle reading key data, peer-info, username/password, OCC
  * from the TLS control channel (cleartext).
@@ -2529,9 +2524,9 @@
             goto error;
         }
         /* read type */
-        uint16_t type = buf_read_u16(buf);
-        uint16_t len = buf_read_u16(buf);
-        if (buf_len(buf) < len)
+        int type = buf_read_u16(buf);
+        int len = buf_read_u16(buf);
+        if (type < 0 || len < 0 || buf_len(buf) < len)
         {
             goto error;
         }
@@ -2543,7 +2538,7 @@
                 {
                     goto error;
                 }
-                uint16_t flags = buf_read_u16(buf);
+                int flags = buf_read_u16(buf);
 
                 if (flags & EARLY_NEG_FLAG_RESEND_WKC)
                 {
@@ -3971,10 +3966,6 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 void
 tls_prepend_opcode_v1(const struct tls_multi *multi, struct buffer *buf)
 {
#7 lore raw

[Openvpn-devel] [PATCH applied] Re: ssl: Clean up type handling in parse_early_negotiation_tlvs()

And with that, the #pragma in ssl.c can finally go...

Change makes sense (took me a bit to understand the intricacies of buf_read_u16() and why it's not returning an uint16_t) - and this is arguably more correct, as the old code did not handle the "buffer too small" case nicely (it did, by having "len" end up being 0xffff, and buf_len() will then be 0 or 1, which is definitely smaller then "len" - but now it's quite explicit and easier to understand).

Smoke tested on Linux.

Your patch has been applied to the master branch.

commit abe32bce066ccf77db7e49159ea0f8111c02a3c4

Author: Frank Lichtenheld
Date:   Sun Nov 16 22:54:27 2025 +0100
     ssl: Clean up type handling in parse_early_negotiation_tlvs()

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1302
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg34487.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#8 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#7) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1302?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2

Change subject: ssl: Clean up type handling in parse_early_negotiation_tlvs()
......................................................................

ssl: Clean up type handling in parse_early_negotiation_tlvs()

buf_read_u16 does not return uint16_t.

Change-Id Ie7ad637223c332f7611c09b20a8d7a3a92d97ec7

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1302
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg34487.html

---
M src/openvpn/ssl.c

1 file changed, 4 insertions(+), 13 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/02/1302/7

src/openvpn/ssl.c +4 -13
index 4841837..8501693 100644
@@ -2194,11 +2194,6 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 /**
  * Handle reading key data, peer-info, username/password, OCC
  * from the TLS control channel (cleartext).
@@ -2522,9 +2517,9 @@
             goto error;
         }
         /* read type */
-        uint16_t type = buf_read_u16(buf);
-        uint16_t len = buf_read_u16(buf);
-        if (buf_len(buf) < len)
+        int type = buf_read_u16(buf);
+        int len = buf_read_u16(buf);
+        if (type < 0 || len < 0 || buf_len(buf) < len)
         {
             goto error;
         }
@@ -2536,7 +2531,7 @@
                 {
                     goto error;
                 }
-                uint16_t flags = buf_read_u16(buf);
+                int flags = buf_read_u16(buf);
 
                 if (flags & EARLY_NEG_FLAG_RESEND_WKC)
                 {
@@ -3963,10 +3958,6 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 void
 tls_prepend_opcode_v1(const struct tls_multi *multi, struct buffer *buf)
 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1302?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie7ad637223c332f7611c09b20a8d7a3a92d97ec7
Gerrit-Change-Number: 1302
Gerrit-PatchSet: 7
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>

#9 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1302?usp=email )

Change subject: ssl: Clean up type handling in parse_early_negotiation_tlvs()
......................................................................

ssl: Clean up type handling in parse_early_negotiation_tlvs()

buf_read_u16 does not return uint16_t.

Change-Id Ie7ad637223c332f7611c09b20a8d7a3a92d97ec7

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1302
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg34487.html

---
M src/openvpn/ssl.c

1 file changed, 4 insertions(+), 13 deletions(-)
src/openvpn/ssl.c +4 -13
index 4841837..8501693 100644
@@ -2194,11 +2194,6 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 /**
  * Handle reading key data, peer-info, username/password, OCC
  * from the TLS control channel (cleartext).
@@ -2522,9 +2517,9 @@
             goto error;
         }
         /* read type */
-        uint16_t type = buf_read_u16(buf);
-        uint16_t len = buf_read_u16(buf);
-        if (buf_len(buf) < len)
+        int type = buf_read_u16(buf);
+        int len = buf_read_u16(buf);
+        if (type < 0 || len < 0 || buf_len(buf) < len)
         {
             goto error;
         }
@@ -2536,7 +2531,7 @@
                 {
                     goto error;
                 }
-                uint16_t flags = buf_read_u16(buf);
+                int flags = buf_read_u16(buf);
 
                 if (flags & EARLY_NEG_FLAG_RESEND_WKC)
                 {
@@ -3963,10 +3958,6 @@
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 void
 tls_prepend_opcode_v1(const struct tls_multi *multi, struct buffer *buf)
 {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1302?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie7ad637223c332f7611c09b20a8d7a3a92d97ec7
Gerrit-Change-Number: 1302
Gerrit-PatchSet: 7
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>